import { Category } from 'src/category/category.entity';
import { PhotoLike } from 'src/photo-like/photo-like.entity';
import { User } from 'src/user/user.entity';
import { Column, Entity, PrimaryGeneratedColumn, ManyToOne, JoinColumn, JoinTable, OneToMany } from 'typeorm';

@Entity('photo')
export class Photo {
  /**
   * 自增主键
   */
  @PrimaryGeneratedColumn({
    comment: '自增ID'
  })
  id: number;

  @Column({
    comment: '图片地址'
  })
  img_url: string;

  @Column({
    comment: '标题'
  })
  title: string;

  @Column({
    comment: '描述'
  })
  content: string;

  @Column({
    comment: '分类'
  })
  category_id: number;

  @Column({
    comment: '点赞数'
  })
  like_num: string;

  @Column({
    comment: '分享数'
  })
  share_num: string;

  @Column({
    comment: '下载数'
  })
  download_num: number;

  @Column({
    comment: '用户id'
  })
  user_id: number;

  @Column({
    comment: '创建时间'
  })
  create_time: number;

  @Column({
    comment: '更新时间'
  })
  update_time: number;

  @Column({
    comment: '删除时间'
  })
  delete_time: number;

  @ManyToOne((type) => User, (user) => user.photos)
  @JoinColumn({ name: 'user_id' })
  user: User;

  @ManyToOne((type) => Category, (category) => category.photos)
  @JoinColumn({ name: 'category_id' })
  category: Category;

  @OneToMany((type) => PhotoLike, (photo) => photo.user)
  @JoinColumn({ name: 'photo_id' })
  photo_like: PhotoLike[];
}